package com.share.interceptor;

import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.lang.reflect.Method;
import java.util.Properties;

/**
 * author:caifan
 * date:2020/2/7
 */
@Intercepts({@Signature(
        type= ParameterHandler.class,
        method = "getParameterObject",
        args = {})})
public class ParameterHandlerInterceptor implements Interceptor {
    private Properties properties = new Properties();
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("ParameterHandlerInterceptor:");
        Object[] args = invocation.getArgs();
        for (Object obj : args) {
            System.out.println(obj.toString());
        }
        Method method = invocation.getMethod();
        System.out.println("method:" + method.getName());
        Object target = invocation.getTarget();
        System.out.println("target:" + target.toString());
        Object proceed = invocation.proceed();
        System.out.println("proceed:" + proceed.toString());
        System.out.println("===============");
        return proceed;
    }

    @Override
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
}
